package com.nbufe.domain.entity;

import com.alibaba.fastjson2.JSON;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.nbufe.domain.dto.target.AddTargetDto;
import com.nbufe.domain.dto.target.EditTargetDto;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Date;
import java.util.List;

/**
 * (CarbonTarget)表实体类
 *
 * @author luzhiheng
 * @since 2024-01-10 10:28:34
 */
@SuppressWarnings("serial")
@Data
@AllArgsConstructor
@NoArgsConstructor
@TableName("carbon_target")
public class CarbonTarget {
    @TableId
    private Long id;

    /**
     * 目标名称
     */
    private String name;

    /**
     * 开始年月
     */
    private String beginDate;

    /**
     * 结束年月
     */
    private String endDate;

    /**
     * 目标排放量
     */
    private Double targetAmount;

    /**
     * 是否启用（0否 1是）
     */
    private Integer enable;

    /**
     * 统计阶段
     */
    private String stageList;

    /**
     * 统计工序
     */
    private String processList;

    /**
     * 备注
     */
    private String remark;

    /**
     * 租户id
     */
    private Integer tenantId;

    @TableLogic
    private Integer delFlag = 0;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date createTime;

    private String createName;

    /**
     * 预警百分比
     */
    private Integer warningPercent = 0;

    public CarbonTarget(AddTargetDto dto) {
        String name = dto.getName();
        String beginDate = dto.getBeginDate();
        String endDate = dto.getEndDate();
        Double targetAmount = dto.getTargetAmount();
        Boolean enable = dto.getEnable();
        List<String> stageList = dto.getStageList();
        List<String> processList = dto.getProcessList();
        String remark = dto.getRemark();
        this.setName(name);
        this.setBeginDate(beginDate);
        this.setEndDate(endDate);
        this.setTargetAmount(targetAmount);
        this.setEnable(enable ? 1 : 0);
        this.setStageList(JSON.toJSONString(stageList));
        this.setProcessList(JSON.toJSONString(processList));
        this.setRemark(remark);
        this.setCreateTime(new Date());
        this.warningPercent = dto.getWarningPercent();
    }

    public void setEditTarget(EditTargetDto dto) {
        String name = dto.getName();
        String beginDate = dto.getBeginDate();
        String endDate = dto.getEndDate();
        Double targetAmount = dto.getTargetAmount();
        List<String> stageList = dto.getStageList();
        List<String> processList = dto.getProcessList();
        String remark = dto.getRemark();
        this.setName(name);
        this.setBeginDate(beginDate);
        this.setEndDate(endDate);
        this.setTargetAmount(targetAmount);
        this.setStageList(JSON.toJSONString(stageList));
        this.setProcessList(JSON.toJSONString(processList));
        this.setRemark(remark);
        this.warningPercent = dto.getWarningPercent();
    }
}
